package com.wwy.arithmetic.newsuanfa;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王伟羽
 * @program: arithmetictest
 * @description: 二叉树中序遍历
 * @create: 2025/04/07
 */

public class Zhongxubianli {

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode() {}
     * TreeNode(int val) { this.val = val; }
     * TreeNode(int val, TreeNode left, TreeNode right) {
     * this.val = val;
     * this.left = left;
     * this.right = right;
     * }
     * }
     */

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        getRootNum(root,list);
        return list;
    }

    static void getRootNum(TreeNode root, List<Integer> list) {
        if (root != null) {
            getRootNum(root.left, list);
            list.add(root.val);
            getRootNum(root.right, list);
        }
    }

}
